import { Column, Entity, Index, ManyToOne } from 'typeorm';
import { CommonEntity, CommonStatus } from '~/common/entity/common.entity';
import { MissionType } from '~/modules/mission/mission.model';
import { UserEntity } from '~/modules/user/user.entity';

@Entity('ah_points_log')
@Index(['id'])
export class PointsLogEntity extends CommonEntity {
  @Column({ type: 'varchar', length: 255, comment: '积分变动标题', nullable: true, default: null })
  title: string;

  @Column({ type: 'int', comment: '积分', default: 0, nullable: false })
  points: number; // 积分

  // 加入积分的类型
  @Column({
    type: 'tinyint',
    width: 1,
    comment: '积分类型',
    default: CommonStatus.YES,
    nullable: false,
  })
  pointsType: number; // 积分类型

  @Column({
    type: 'tinyint',
    width: 1,
    comment: '是否已发放奖励',
    default: CommonStatus.NO,
  })
  hasReward: CommonStatus; // 是否已发放奖励

  @Column({ type: 'int', comment: '任务ID', name: 'mission_id', nullable: true, default: null })
  missionId: number;

  @Column({
    type: 'varchar',
		length: 50,
		comment: '任务类型',
		name: 'mission_type',
		nullable: true,
  })
  missionType: string;

  @Column({
    type: 'varchar',
    length: 255,
    comment: '任务关联数据',
    name: 'mission_related_data',
    nullable: true,
    default: null,
  })
  missionRelatedData: string; // 任务关联数据

  @ManyToOne(() => UserEntity, (user) => user.pointsLog)
  user: UserEntity;
}
